local sk__zhanjue = fk.CreateSkill {

  name = "sk__zhanjue",

  tags = {  },

}



sk__zhanjue:addEffect(fk.AfterCardsMove, {
  name = "sk__zhanjue",
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__zhanjue.name) then
      local n = {}
      for _, move in ipairs(data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand and player:isKongcheng()) then
              table.insertIfNeed(n, Card.PlayerHand)
            end
            if info.fromArea == Card.PlayerEquip and #player:getCardIds("e") == 0 then
              table.insertIfNeed(n, Card.PlayerEquip)
            end
            if info.fromArea == Card.PlayerJudge and #player:getCardIds("j") == 0 then
              table.insertIfNeed(n, Card.PlayerJudge)
            end
          end
        end
      end
      if #n > 0 then
        event:setCostData(self, #n)
        return true
      end
    end
  end,
  on_trigger = function (self, event, target, player, data)
    self.cancel_cost = false
    local n = event:getCostData(self)
    for _ = 1, n do
      if not player:hasSkill(sk__zhanjue.name) or self.cancel_cost then return end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local alivePlayerIds = table.map(player.room.alive_players, Util.IdMapper)
    local to = player.room:askForChoosePlayers(player, alivePlayerIds, 1, 1,
      "#sk__zhanjue-choose", sk__zhanjue.name, true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:damage({
      from = player,
      to = room:getPlayerById(event:getCostData(self)),
      damage = 1,
      skillName = sk__zhanjue.name,
    })
  end,
})

return sk__zhanjue